/**
 * 
 */
package com.wolfpire.workflow.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wolfpire.system.common.EasyuiPage;
import com.wolfpire.system.common.EasyuiPagination;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.Result;
import com.wolfpire.workflow.om.Operate;
import com.wolfpire.workflow.spring.OperateService;

/**
 * 操作管理控制器
 * @author lihd
 *
 */

@Controller
@RequestMapping("/operate")
public class OperateController {
	
	@Resource OperateService operateService;
	
	@RequestMapping("/list")
	public ModelAndView list() {
		return new ModelAndView("workflow/operate/operate_list");
	}
	
	@ResponseBody
	@RequestMapping("/queryList")
	public EasyuiPagination<Operate> queryList(EasyuiPage<Operate> page, Operate filterOperate) {
		Page<Operate> operates = this.operateService.setPageDataList(page, filterOperate);
		return new EasyuiPagination<Operate>(operates);
	}
	
	@RequestMapping(value = "/add")
	public ModelAndView add(HttpSession session) {
		ModelAndView mv = new ModelAndView("workflow/operate/operate_edit");
		mv.getModelMap().put("operate", new Operate());
		return mv;
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(Long operateId) {
		ModelAndView mv = new ModelAndView("workflow/operate/operate_edit");
		if (null != operateId) {
			Operate operate = this.operateService.get(operateId);
			mv.getModelMap().put("operate", operate);
		}
		return mv;
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public Result delete(Long operateId) {
		try {
			this.operateService.delete(operateId);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
	
	@ResponseBody
	@RequestMapping("/save")
	public Result save(Operate operate) {
		try {
			this.operateService.saveOrUpdate(operate);
			return new Result(true, "保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "保存失败");
		}
	}
	
}
